package com.yuncheng.spcyApi.controller;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.bo.ParamsBo;
import com.yuncheng.spcyApi.constant.common.SpcyCommonConstant;
import com.yuncheng.spcyApi.entity.SpcyRsNotice;
import com.yuncheng.spcyApi.service.ISpcyRsNoticeService;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

@Api(tags = "系统通告-接口")
@RestController
@RequestMapping(value = "/api/spzx-spcy/notice")
public class SpcyRsNoticeController {

    @Resource
    private ISpcyRsNoticeService spcyRsNoticeService;

    @Log(title = "公告-分页查询")
    @ApiOperation(value = "公告-分页查询")
    @GetMapping(value = "queryPageNotice")
    public HttpResult queryPageNotice(SpcyRsNotice notice,
                                      @RequestParam(value = "startTime",defaultValue = "")String startTime,
                                      @RequestParam(value = "endTime",defaultValue = "")String endTime,
                                      @RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo,
                                      @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                                      OrderItemVo orderItemVo){

        return HttpResult.ok(spcyRsNoticeService.queryPageNotice(notice, startTime, endTime, pageNo, pageSize,orderItemVo));
    }

    @Log(title = "有效公告-分页查询")
    @ApiOperation(value = "有效公告-分页查询")
    @GetMapping(value = "queryPageYxNotice")
    public HttpResult queryPageYxNotice(SpcyRsNotice notice,
                                        @RequestParam(value = "startTime",defaultValue = "")String startTime,
                                        @RequestParam(value = "endTime",defaultValue = "")String endTime,
                                        @RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo,
                                        @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                                        OrderItemVo orderItemVo){
        notice.setFyxzt(SpcyCommonConstant.NOTICE_YXZT_YX);
        return HttpResult.ok(spcyRsNoticeService.queryPageNotice(notice, startTime, endTime,pageNo, pageSize,orderItemVo));
    }

    @Log(title = "添加公告")
    @ApiOperation(value = "添加公告")
    @PostMapping(value = "addNotice")
    public HttpResult addNotice(@RequestBody SpcyRsNotice notice){
        SpcyRsNotice notice1 = spcyRsNoticeService.addNotice(notice);

        HttpResult result = new HttpResult(true);
        result.setMessage("保存成功");
        result.setResult(notice1);
        return result;
    }

    @Log(title = "更新公告")
    @ApiOperation(value = "更新公告")
    @PutMapping(value = "updateNotice")
    public HttpResult updateNotice(@RequestBody HashMap<String,Object> paramMap){

        spcyRsNoticeService.updateNotice(paramMap);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "批量删除公告")
    @ApiOperation(value = "批量删除公告")
    @PostMapping(value = "deleteNotice")
    public HttpResult deleteNotice(@RequestBody ParamsBo paramsBo){

        spcyRsNoticeService.deleteNotice(paramsBo);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "查看公告")
    @ApiOperation(value = "查看公告")
    @GetMapping(value = "queryById")
    public HttpResult queryById(String id){

        return HttpResult.ok(spcyRsNoticeService.queryById(id));
    }

}
